Skip to content

update MMU code #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

update MMU code #39

wants to merge 3 commits into from

Conversation

robamu
Copy link
Contributor

@robamu robamu commented Jun 23, 2025

Still needs to be tested

@robamu robamu force-pushed the update-mmu-structures branch from 44f73e9 to 4a10229 Compare July 16, 2025 13:52
@robamu
Copy link
Contributor Author

robamu commented Jul 16, 2025

I used and tested this as part of a zynq7000 ethernet implementation now.

@robamu robamu marked this pull request as ready for review July 16, 2025 13:54
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SectionAttributes {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bitbybit::bitfield struct may be easier to use here.

Copy link
Contributor Author

@robamu robamu Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, that need is covered by the L1Section. This is more of a high-level attribute collection which also abstracts the various bits into their high-level meaning. Maybe a section_attribute method for the L1 section would be better? It does a lot of stuff usually covered by bitbybit though, admittedly..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just seems unnecessary to have to do all the shifting manually.

Perhaps you could have a public type which is normal, and a private type that is a bitbybit bitfield, and an Into impl to convert between them. Then you can let bitfield macro do the hard work, but it's not in the public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding this API for the L1 section:

    #[inline]
    pub fn section_attrs(&self) -> Result<SectionAttributes, InvalidL1EntryType> {
        SectionAttributes::from_raw(self.raw_value())
    }

    #[inline]
    pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) {
        self.raw_value = self.base_addr().as_u32() | section_attrs.raw();
    }

Copy link
Contributor Author

@robamu robamu Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I'll have a look at bitbybit to avoid the boilerplate bit shifting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, maybe? I don't have a good handle on how this API is used.

Copy link
Contributor Author

@robamu robamu Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll figure out something that makes sense :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I updated the API. Less bitshifting, and it is actually a lot better from a user perspective as well.

@robamu robamu force-pushed the update-mmu-structures branch from e464ad7 to 03501fe Compare July 16, 2025 16:06
pub struct L1Section {
/// Section base address.
#[bits(20..=31, rw)]
base_addr: u12,
/// Non-global bit.
#[bit(16, rw)]
#[bit(17, rw)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worrying that I just found this because I wanted to add a builder..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit PR for this bugfix: #45

#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SectionAttributes {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I updated the API. Less bitshifting, and it is actually a lot better from a user perspective as well.

#[inline]
pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) {
self.raw_value =
((self.base_addr().value() as u32) << 20) | section_attrs.l1_section_part().raw_value();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: I could also write this using the builder API. It would be very verbose, but shouldn't matter for performance.

| ((section_attrs.memory_attrs.b as u32) << 2)
| L1EntryType::Section as u32;
Self::new_with_raw_value(raw)
Self::new_with_raw_value((higher_bits << 20) | section_attrs.l1_section_part().raw_value())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also write this using the builder API. It would be very verbose, but shouldn't matter for performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /// Set the section attributes without changing the address.
    #[inline]
    pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) {
        let attrs = section_attrs.l1_section_part();
        *self = L1Section::builder()
            .with_base_addr(self.base_addr())
            .with_ng(attrs.ng())
            .with_s(attrs.s())
            .with_apx(attrs.apx())
            .with_tex(attrs.tex())
            .with_ap(attrs.ap())
            .with_p_bit(attrs.p_bit())
            .with_domain(attrs.domain())
            .with_xn(attrs.xn())
            .with_c(attrs.c())
            .with_b(attrs.b())
            .with_entry_type(attrs.entry_type())
            .build()
    }

to be honest, I prefer the first one..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants